package com.shuai.dynamicProxy.cglib.proxy;

import com.shuai.staticProxy.impl.UserServiceImpl;
import com.shuai.staticProxy.service.UserService;
import lombok.Data;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author shuaihong-coding
 * @date 2025/10/3
 * @className UserServiceInvocationHandler
 */
@Data
public class UserServiceCglibInterceptor implements MethodInterceptor {

    private UserService userService;

    public UserServiceCglibInterceptor(UserService target) {
        this.userService = target;
    }
    public UserServiceCglibInterceptor(){
        this.userService = new UserServiceImpl();
    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("我是cglib动态代理 --- 我要开始查询用户" + Arrays.toString(objects) + "的信息了");
        return method.invoke(userService, objects);
    }
}
